import { getPage, get } from '../../request'

const ns = '/flw/flow-def'

export const flowDefApi = {
  /**
   * 查询所有流程定义
   * @param params
   * @returns
   */
  findDefList: () => {
    return get({ url: `${ns}/list` })
  },

  /**
   * 查询分页流程定义
   * @param params
   * @returns
   */
  findDefPage: (page: AxiosType.Pagination, params?: { [key: string]: any }) => {
    return getPage({ url: `${ns}/page`, params }, page)
  },

  /**
   * 检查key是否存在
   * @param key
   * @returns
   */
  checkKey: (key: string) => {
    return get({ url: `${ns}/check-key/${key}` })
  },

  /**
   * 检查name是否存在
   * @param name
   * @returns
   */
  checkName: (name: string) => {
    return get({ url: `${ns}/check-name/${name}` })
  },

  /**
   * 查询流程定义的userTask
   * @param key
   * @param id
   * @returns
   */
  findUserTask: (key: string, id: string) => {
    let url = `${ns}/user-task/def-key/${key}`
    if (id) {
      url = `${ns}/user-task/def-id/${id}`
    }
    return get({ url })
  }
}
